#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sdt

import numpy as np
import matplotlib.pyplot as plt

def compress(s,x,y):
	xx=[]
	yy=[]
	for i in range(len(x)):
		xi = x[i]
		yi = y[i]
		dx,dy = s.check((xi,yi))
		if dx!=None and dy!=None:
			xx.append(dx)
			yy.append(dy)
			print (dx,dy),True
		else:
			pass #print (dy,dy),False
	return xx,yy

import random,math
def job():
	scale = 100;flags=[-1,1]
	s = sdt.SDT(0.005*scale)
	x = np.arange(0,2*np.pi,0.01)
	y = np.sin(x)*scale
	x = [t for t in x]
	y = [t+(([-1,1]+[0]*98)[random.randint(0,100)%100])*scale*min(0.02,random.random()) for t in y];#[t+0.1*random.randint(0,int(t*(10*random.random()))) for t in y]
	cx,cy = compress(s,x,y)
	cx.append(x[-1])
	cy.append(y[-1])
    
	plt.grid(True, linewidth = "0.5")
	plt.plot(x,y)
	plt.xlabel("x")
	plt.ylabel("y")
	#print x
	#print y
	#print cx
	#print cy
	print len(cx),len(x),float(len(cx))/float(len(x))
	plt.plot(cx,cy,".")
	plt.show()
	
job()


